﻿using NUnit.Framework;
using ValidationFramework.Reflection;
using ValidationFramework.Tests.Performance.TestHelpers;

namespace ValidationFramework.Tests.Performance
{
	[TestFixture]
	public class ValidationFacadeTests
	{
		public class ClassToValidate
		{
			public int PropertyToValidate
			{
				get;
				set;
			}
		}
#if (!WindowsCE)
		[Test]
		public void Overhead_From_Using_Facade_To_Validate()
		{
			// --- Arrange
			// Arrange
			Validation.Initialize();
			Validation.ConfigurePolicyFor<ClassToValidate>(x => x.Ensure(y => y.PropertyToValidate).Passes(new AlwaysPassValidator()));

			const int iterations = 10000;
			var classToValidate = new ClassToValidate { PropertyToValidate = 10 };
			const string memberName = "PropertyToValidate";

			// --- ACT
			var options = new ValidationOptions();
			using (var disposableStopwatch = new DisposableStopwatch("Validate Valid Property using string", iterations))
			{
				disposableStopwatch.Run(() => Assert.AreEqual(Validation.Validate(classToValidate, memberName, options).Count, 0));
			}
		}
		[Test]
		public void Validate_Invalid_Property_Using_Facade()
		{
			// Arrange
			Validation.Initialize();
			Validation.ConfigurePolicyFor<ClassToValidate>(x => x.Ensure(y => y.PropertyToValidate).Passes(new AlwaysPassValidator()));

			const int iterations = 10000;
			var classToValidate = new ClassToValidate { PropertyToValidate = 10 };
			const string memberName = "PropertyToValidate";

			// ACT
			var options = new ValidationOptions();
			var validationManager = Validation.GetPropertyValidationManager(classToValidate);
			using (var disposableStopwatch = new DisposableStopwatch("Validate Valid Property using string", iterations))
			{
				disposableStopwatch.Run(() => Validation.Validate(classToValidate, memberName, options));
			}
		}
#endif
	}
}
